<?php

namespace Shop\Providers;

use Illuminate\Support\ServiceProvider;
use Illuminate\Support\Facades\Route;

class ShopServiceProvider extends ServiceProvider
{
    protected $defer = false;
    protected $namespace = 'Shop\Http\Controllers';

    public function boot()
    {
        $this->registerViews();
        $this->registerRoutes();
        $this->registerConfig();
    }

    public function registerViews()
    {
        $viewPath = realpath(__DIR__ . '/../Resources/views/pc/theme/');
        $this->loadViewsFrom($viewPath,'PShop');

        $viewPath = realpath(__DIR__.'/../Resources/views/wap/theme1/');
        $this->loadViewsFrom($viewPath,'WShop');

        $langPath = realpath(__DIR__.'/../Resources/lang');
        $this->loadTranslationsFrom($langPath, 'shop');
    }

    /**
     * @title 注册配置文件
     */
    private function registerConfig()
    {
        $configPath = realpath(__DIR__.'/../Config/mall.php');
        $this->mergeConfigFrom($configPath,'mall');
    }

    public function registerRoutes()
    {
        Route::prefix('shop')
            ->middleware(['web'])
            ->namespace($this->namespace)
            ->group(__DIR__.'/../Routes/web.php');
    }

}
